import axios from 'axios'
import qs from 'qs'

const host = 'https://ceremony.jluzh.com/jluzh_ceremony/api'
const requests = {
    state: {
        api: {
            academic: {
                url: host + '/academic/get',
                method: 'get',
                params: {}
            },
            ceremony: {
                url: host + '/ceremony/get',
                headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                method: 'post',
                data: {}
            }
        }
    },
    mutations: {
        updateAcademicParams: (state, params) => {
            if (params.hasOwnProperty('stu_name')) {
                state.api.academic.params['stu_name'] = params['stu_name']
            }
        },
        updateCeremonyData: (state, data) => {
            if (data.hasOwnProperty('stu_name') && data.hasOwnProperty('ac_name')) {
                data.ex="优秀毕业生"
                state.api.ceremony.data = qs.stringify(data)
            }
        }
    },
    getter: {},
    actions: {
        getAcademics({commit, state}, params) {
            commit('updateAcademicParams', params)
            return axios(state.api.academic)
        },
        getCeremony({commit, state}, data) {
            commit('updateCeremonyData', data)
            return axios(state.api.ceremony)
        }

    }

}
export default requests